<?php

class Zend_View_Helper_Price
{	
	public $currency = array(
		'cs' => 'CZK',
		'en' => 'EUR'
	);
	
	public function Price( $item, $free, $locale, $cur = false , $discount = 0) {
		$currencyValue = false;
		if( $cur ) {
			$Currency = new Currency();
			$items = $Currency->getListService()->toArray();
			$crroz = isSet( $this->currency[$locale] ) ? ' ' . $this->currency[$locale] : ' PLN';
			
			if( $locale != 'pl' ) {
				foreach( $items as $value ) {
					if( $value['name'] == $this->currency[$locale] ) {
						$currencyValue = $value['value'];
					}
				}
			}

		} else {
			$crroz = '';
		}
		$sess = new Zend_Session_Namespace( 'ranks' );
		
		if( count( $sess->data ) > 0 ) {

			foreach( $sess->data as $value ) {
				if( $value['manufacturers_m_id'] == $item['manufacturers_m_id'] ) {
					if( !$currencyValue ) {
						$brutto = 0;
						if( $item['Vat']['rate'] > 0 ) {
							$brutto = ( $item['Dimension'][$free]['price' . $value['rank_id']] * $item['Vat']['rate'] ) / 100;
						}
						$brutto = $brutto + $item['Dimension'][$free]['price' . $value['rank_id']];
						
						return number_format( $brutto, 2, '.', ' ') . $crroz;
					} else {
						$brutto = 0;
						
						$am = $item['Dimension'][$free]['price' . $value['rank_id']];
						
						if( $item['Vat']['rate'] > 0 ) {
							$brutto = ( $am * $item['Vat']['rate'] ) / 100;
						}
						
						$brutto = $am + $brutto;
						
						$am = $brutto / $currencyValue;

						return number_format( $am, 2, '.', ' ') . $crroz;
					}
				}
			}
		} else {
			if( !$currencyValue ) {
				$brutto = 0;
				if( $item['Vat']['rate'] > 0 ) {
					$brutto = ( $item['Dimension'][$free]['price1'] * $item['Vat']['rate'] ) / 100;
				}
				$brutto = $brutto + $item['Dimension'][$free]['price1'];
				
				return number_format( $brutto, 2, '.', ' ') . $crroz;
			} else {
				$brutto = 0;
				$am = $item['Dimension'][$free]['price1'];

				if( $item['Vat']['rate'] ) {
					$brutto = ( $am * $item['Vat']['rate'] ) / 100;
				}
				$brutto = $brutto + $am;
				
				$am = $brutto / $currencyValue;
				
				return number_format( $am, 2, '.', ' ') . $crroz;
			}
		}
	}
}